﻿<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
  <meta http-equiv="Cache-Control" content="no-siteapp"/>
  <!--[if lt IE 9]>
  <script type="text/javascript" src="lib/html5shiv.js"></script>
  <script type="text/javascript" src="lib/respond.min.js"></script>
  <![endif]-->
  <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
  <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
  <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
  <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
  <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
  <!--[if IE 6]>
  <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
  <script>DD_belatedPNG.fix('*');</script>
  <![endif]-->
  <title>建材列表</title>
</head>
<body class="pos-r">
<div style="margin-left:10px;">
  <nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 借款列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
  <div class="page-container">
    <div class="text-c">
      <input type="text" id="title" placeholder=" 标的名称" style="width:250px" class="input-text">
      日期范围：
      <input type="text" id="start_date" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'start_date\')||\'%y-%M-%d\'}' })" class="input-text Wdate" style="width:120px;"> -
      <input type="text" id="end_date" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'end_date\')}',maxDate:'%y-%M-%d' })" class="input-text Wdate" style="width:120px;">
      <button class="btn btn-success" onclick="searchBorrowList()"><i class="Hui-iconfont">&#xe665;</i> 搜索标的</button>
    </div>
    <div class="mt-20">
      <table id="borrowList" class="table table-border table-bordered table-bg table-hover table-sort">
        <thead>
        <tr class="text-c">
          <th width="20">ID</th>
          <th width="60">名称</th>
          <th width="20">借款金额</th>
          <th width="20">年华利率</th>
          <th width="20">借款期限</th>
          <th width="20">状态</th>
          <th width="40">操作</th>
        </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
    </div>
  </div>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="static/etl/js/util.js"></script>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
  var borrowListTable = $('#borrowList').dataTable({
    "ajax": {
      "url": "/borrow/list",
      "data": {
        "status": getUrlParam("status")
      }
//      "dataSrc": function(jsondata){
//        return jsondata.data;
//      }
    },
    "columns": [
      {"data": "borrowId"},
      {"data": "title"},
      {"data": "amount"},
      {"data": "apr"},
      {"data": "period"},
      {"data": "status"},
      {"render": function(data, type, row, meta) { // 最后一列
        return '<a style="text-decoration:none" onClick="product_stop(this,'+ row.borrowId +')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>' +
          '<a style="text-decoration:none" class="ml-5" onClick="product_edit("产品编辑","product-add.html",'+ row.borrowId +')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>' +
          '<a style="text-decoration:none" class="ml-5" onClick="product_del(this,'+ row.borrowId +')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>'
          ;
      }
      }
    ],
    "bFilter": false, // 去掉从当前数据中检索
    "bLengthChange": false, // 去掉每页显示多少条数据
    "bStateSave": true, //状态保存
    "aaSorting": [[0, "desc"]], //默认第几个排序
    "aoColumnDefs": [
      {"orderable": false, "aTargets": [1, 5, 6]} // 指定列不参与排序，多个用,隔开
    ],
    "bDestroy": true,
    "serverSide": true, // 服务端分页
    "iDisplayLength" : 20, // 每页显示行数
    "pageLength" : 13,
//    "displayStart": 1, // 初始化显示的时候从第几条数据开始显示(一开始显示第几页)
    "pagingType": "full_numbers",
    "deferRender": true // 延迟加载
  });

  function searchBorrowList() {
    var param = {
      "title": $("#title").val(),
      "start_date": $("#start_date").val(),
      "end_date": $("#end_date").val()
    };
    borrowListTable.dataTableSettings[0].ajax.data = param;
  }

  /*产品-下架*/
  function product_stop(obj, id) {
    layer.confirm('确认要下架吗？', function (index) {
      $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,id)" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
      $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
      $(obj).remove();
      layer.msg('已下架!', {icon: 5, time: 1000});
    });
  }

  /*产品-编辑*/
  function product_edit(title, url, id) {
    var index = layer.open({
      type: 2,
      title: title,
      content: url
    });
    layer.full(index);
  }

  /*产品-删除*/
  function product_del(obj, id) {
    layer.confirm('确认要删除吗？', function (index) {
      $.ajax({
        type: 'POST',
        url: '/borrow/del',
        dataType: 'json',
        data: {
          "borrowId": id
        },
        success: function (data) {
          if(data.code == 100){
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
          } else {
            layer.msg(data.message, {icon: 2, time: 1000});
          }
        },
        error: function (data) {
          console.log(data.msg);
        },
      });
    });
  }
</script>
</body>
</html>